# -*- coding: utf-8 -*-
'''
Created on Apr 23, 2011

@author: "Yang Sun"
'''
import urllib2, re
     
def getHttpData(url):        
    req = urllib2.Request(url)
    req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
    response = urllib2.urlopen(req)
    httpdata = response.read()
    response.close()
    return httpdata

''''
def getHttpData(url):
    passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    passmgr.add_password(None, 'http://152.159.215.21:8080', 'yang_sun', '1etme1nCPIQ')    
    authinfo = urllib2.ProxyBasicAuthHandler(passmgr)
    proxy_support = urllib2.ProxyHandler({'http' : 'http://152.159.215.21:8080'})
    opener = urllib2.build_opener(authinfo, proxy_support)
    urllib2.install_opener(opener)
    response = urllib2.urlopen(url)
    httpdata = response.read()    
    return httpdata
'''
    
def getHttpDataCompact(url):        
    httpdata = getHttpData(url)
    httpdata = re.sub('\s', '', httpdata)
    return httpdata
        